package com.intellagric.service.iftmonitor.Impl.ift_ctrl_equipment;

import com.github.pagehelper.PageHelper;
import com.intellagric.common.pojo.LayuiDataGridResult;
import com.intellagric.common.pojo.ResponseMessage;
import com.intellagric.dao.iftmonitor.CtrlEquipmentStatusDao;
import com.intellagric.mapper.IftCtrlEquipmentStatusMapper;
import com.intellagric.module.iftmonitor.CtrlEquipmentStatusVo;
import com.intellagric.pojo.IftCtrlEquipmentStatus;
import com.intellagric.pojo.IftCtrlEquipmentStatusExample;
import com.intellagric.service.iftmonitor.ift_ctrl_equipment.CtrlEquipmentStatusService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: zhy
 * @email: 1269679946@qq.com
 * @Date: 2018/10/21
 * @DESC： 控制设备状态管理服务实现
 */
@Service
public class CtrlEquipmentStatusServiceImpl implements CtrlEquipmentStatusService {

    @Autowired
    private IftCtrlEquipmentStatusMapper ctrlEquipmentStatusMapper;

    @Autowired
    private CtrlEquipmentStatusDao ctrlEquipmentStatusDao;

    /**
     * 添加控制状态设备信息
     * @param ctrlEquipmentStatus
     * @return ResponseMessage
     */
    @Override
    public ResponseMessage addCtrlEquipmentStatus(IftCtrlEquipmentStatus ctrlEquipmentStatus) {
        if (ctrlEquipmentStatusMapper.insertSelective(ctrlEquipmentStatus) == 1) {
            return ResponseMessage.success();
        } else {
            return ResponseMessage.fail();
        }
    }

    /**
     * 删除控制状态设备信息
     * @param id
     * @return ResponseMessage
     */
    @Override
    public ResponseMessage deleteCtrlEquipmentStatus(String id) {
        if (ctrlEquipmentStatusMapper.deleteByPrimaryKey(id) == 1) {
            return ResponseMessage.success();
        } else {
            return ResponseMessage.fail();
        }
    }

    /**
     * 修改控制状态设备信息
     * @param ctrlEquipmentStatus
     * @return ResponseMessage
     */
    @Override
    public ResponseMessage editCtrlEquipmentStatus(IftCtrlEquipmentStatus ctrlEquipmentStatus) {
        if (ctrlEquipmentStatusMapper.updateByPrimaryKeySelective(ctrlEquipmentStatus) == 1) {
            return ResponseMessage.success();
        } else {
            return ResponseMessage.fail();
        }
    }

    /**
     * 查询控制设备状态信息
     * @param id
     * @return IftCtrlEquipmentStatus
     */
    @Override
    public IftCtrlEquipmentStatus getCtrlEquipmentStatusById(String id) {
        return ctrlEquipmentStatusMapper.selectByPrimaryKey(id);
    }

    /**
     * 查询控制设备状态信息列表
     * @return LayuiDataGridResult
     */
    @Override
    public LayuiDataGridResult getCtrlEquipmentStatusList() {
        IftCtrlEquipmentStatusExample ctrlEquipmentStatusExample = new IftCtrlEquipmentStatusExample();
        ctrlEquipmentStatusExample.createCriteria().andIdIsNotNull();
        List<IftCtrlEquipmentStatus> ctrlEquipmentStatusList = ctrlEquipmentStatusMapper.selectByExample(ctrlEquipmentStatusExample);
        return LayuiDataGridResult.success().add(ctrlEquipmentStatusList,ctrlEquipmentStatusList.size());
    }

    /**
     * 多条件查询控制设备状态信息列表
     * @param ctrlEquipmentStatusVo
     * @return LayuiDataGridResult
     */
    @Override
    public LayuiDataGridResult getCtrlEquipmentStatusListByVo(CtrlEquipmentStatusVo ctrlEquipmentStatusVo) {
        List<IftCtrlEquipmentStatus> ctrlEquipmentStatusList = ctrlEquipmentStatusDao.selectCtrlEquipmentStatusListByVo(ctrlEquipmentStatusVo);
        return LayuiDataGridResult.success().add(ctrlEquipmentStatusList,ctrlEquipmentStatusList.size());
    }

    /**
     * 分页查询控制设备状态信息列表
     * @param page
     * @param rows
     * @return LayuiDataGridResult
     */
    @Override
    public LayuiDataGridResult getCtrlEquipmentStatusPage(int page, int rows) {
        PageHelper.startPage(page,rows);
        IftCtrlEquipmentStatusExample ctrlEquipmentStatusExample = new IftCtrlEquipmentStatusExample();
        ctrlEquipmentStatusExample.createCriteria().andIdIsNotNull();
        List<IftCtrlEquipmentStatus> ctrlEquipmentStatusList = ctrlEquipmentStatusMapper.selectByExample(ctrlEquipmentStatusExample);
        LayuiDataGridResult result = new LayuiDataGridResult();
        result.setData(ctrlEquipmentStatusList);
        return result;
    }


}
